define(function(){
	$('#switch>li').on('click',function(){
		var id = $(this).attr('id');
		$(this).addClass('active').siblings().removeClass('active');
		if(id==1){
			$('.panel2').removeClass('hide1').addClass('show1');
			$('.panel1').removeClass('show1').addClass('hide');
		}else{
			$('.panel1').removeClass('hide').addClass('show1');
			$('.panel2').removeClass('show1').addClass('hide1');
		}
	})
	//删除按钮
	$("button[id*='delete']").on('click',function(){
		$('#deleteModel').modal({
  			keyboard:true,
  			show:true
		})
		var id = parseInt($(this).attr('id'));
		$('#deletp').on('click',function(){
			var path = window.location.pathname;
			var urls =path+'/delete?id='+id;
			sendajax(urls);
		})
	})
	//更新按钮
	$("button[id*='update']").on('click',function(){
		$('#updateModel').modal({
  			keyboard:true,
  			show:true
		})
		var id = parseInt($(this).attr('id'));
		$('#updatp').on('click',function(){
			var path = window.location.pathname;
			window.location.href =path+'/updatedetail?id='+id;
		})
	})

	//发布按钮
	$("button[id*='fabu']").on('click',function(){
		$('#fabuModel').modal({
  			keyboard:true,
  			show:true
		})
		var id = parseInt($(this).attr('id'));
		$('#fabtp').on('click',function(){
			var path = window.location.pathname;
			var urls =path+'/fabu?id='+id;
			sendajax(urls);
		})
	});

	//查看投递信息按钮
	$("button[id*='visit']").on('click',function(){
		var id = parseInt($(this).attr('id'));
		var path = window.location.pathname;
		window.location.href =path+'/visit?id='+id;
	});

	//查看详细投递信息
	$("button[id*='person']").on('click',function(){
		var id = parseInt($(this).attr('id'));
		var path = window.location.pathname;
		window.location.href ='../detail/person?id='+id;
	});

	//取消按钮
	$("button[id*='cancel']").on('click',function(){
		$('#cancelModel').modal({
  			keyboard:true,
  			show:true
		})
		var id = parseInt($(this).attr('id'));
		$('#cancep').on('click',function(){
			var path = window.location.pathname;
			var urls =path+'/cancel?id='+id;
			sendajax(urls);
		})
	});

	if(typeof FileReader == 'undefined'){
		alert('您的浏览器版本过低!请您更换高版本浏览器后继续访问!');
	}

	//上传图片监控
	$('#backgroundimage').on('change',function(e){
		var imginfo = $(this).val();
		if(imginfo.indexOf('.png')==-1&&imginfo.indexOf('.jpg')==-1&&imginfo.indexOf('.gif')==-1){
			alert('请选择格式正确的文件');
		}else{
			var file = document.getElementById('backgroundimage').files[0];
			var reader = new FileReader();
			reader.readAsDataURL(file);
			reader.onload = function(f){
				$('#demoimg').attr('src',this.result);
			}
		}
	})
	//公共ajax参数方法
	function sendajax(urls)
	{
		$.ajax({
			url:urls,
			type:'get',
			success:function(data){
				layer.msg(data.message,function(){
					location.reload();
				});
			}
		})
	}
})